<!doctype html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-model="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

<div id="app">
    <input type="text" v-model="newTodoText" @keyup.enter="addNewTodo" placeholder="Add a todo">
    <ul>
        <li is="todo-item" v-for="(todo,idx) of todos" :key="todo.id" :title="todo.title" @remove-todo="todos.splice(idx,1)"></li>
    </ul>
</div>
</body>
<script src="../../vender/vue@2.4.2.js"></script>
<script>
    Vue.component('todo-item',{
        template:`<li>{{title}}<button @click="$emit('remove-todo')">X</button></li>`,
        props:['title']
    });
    var app=new Vue({
        el:'#app',
        data:{
            newTodoText:'',
            todos:[
                {id:1,title:'Todo-1'},
                {id:2,title:'Todo-2'},
                {id:3,title:'Todo-3'}
            ],
            nextTodId:4
        },
        methods:{
            addNewTodo: function () {
                this.todos.push({
                    id:this.nextTodoId++,
                    title:this.newTodoText
                });
                this.newTodoText='';
            }
        }
    });

</script>
</html>